package softtech.apps.callblocker.adapter;

import java.util.ArrayList;
import java.util.List;

import softtech.apps.callblocker.R;
import softtech.apps.callblocker.model.CallMode;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdapterSmsMode extends BaseAdapter{
	
	private static final String TAG = null;
	Activity activity;
	LayoutInflater inflater;
	private int mode;
	List<CallMode> listMode = new ArrayList<CallMode>();
	
	public AdapterSmsMode(Activity activity, int mode){
		this.activity = activity;
		this.mode = mode;
		
		listMode.add(new CallMode(activity.getResources().getString(R.string.name_modesms1),
				activity.getResources().getString(R.string.content_modesms1), activity.getResources()
						.getDrawable(R.drawable.modesms1)));
		
		listMode.add(new CallMode(activity.getResources().getString(R.string.name_modesms2), 
				activity.getResources().getString(R.string.content_modesms2),
				activity.getResources().getDrawable(R.drawable.modesms2)));
		
		listMode.add(new CallMode(activity.getResources().getString(R.string.name_modesms3),
				activity.getResources().getString(R.string.content_modesms3),
				activity.getResources().getDrawable(R.drawable.modesms3)));
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (listMode.size() <= 0) {
			return 1;
		}
		return listMode.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listMode.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (listMode == null || listMode.equals(null) || listMode.size() == 0) {
			inflater = (LayoutInflater) activity
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.activity_view_profile, null);
			return convertView;
		}
		if (inflater == null) {
			inflater = (LayoutInflater) activity
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		}
		if (convertView == null) {
			convertView = inflater
					.inflate(R.layout.item_dialog_call_mode, null);

		}

		TextView tvNameMode = (TextView) convertView
				.findViewById(R.id.tvNameMode);
		ImageView img = (ImageView) convertView.findViewById(R.id.imgMode);
		TextView tvExplainMode = (TextView) convertView
				.findViewById(R.id.tvExplainMode);

		CallMode item = listMode.get(position);
		tvNameMode.setText(item.getModeName());
		tvExplainMode.setText(item.getExplainMode());
		img.setBackgroundDrawable(item.getIcon());
		convertView.setBackgroundColor(Color.TRANSPARENT);
		int modeSms = mode&15;
		
		// check neu mode sms = voi position nao cua listview thi highlight
		if ( (position +1 )== modeSms) {
			convertView.setBackgroundColor(Color.parseColor("#181c20"));
			tvNameMode.setTextColor(Color.WHITE);
			tvExplainMode.setTextColor(Color.WHITE);
		}else{
			tvNameMode.setTextColor(Color.parseColor("#9fa7b3"));
			tvExplainMode.setTextColor(Color.parseColor("#9fa7b3"));
		}
		return convertView;
	}

}
